package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.PortRuleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by xu_jiaHui on 2017/12/9.
 */
@Controller
@RequestMapping("/rds_portRule")
public class PortRuleController {

    @Resource
    private PortRuleService portRuleService;

    @ResponseBody
    @RequestMapping("/getPortRedRuleById")
    public DTResponseDto getPortRedRuleById(DTRequestDto dtRequestDto, Integer alarmId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = portRuleService.getPortRedRuleById(dtRequestDto, alarmId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @ResponseBody
    @RequestMapping("/getPortBlueRuleById")
    public DTResponseDto getPortBlueRuleById(DTRequestDto dtRequestDto, Integer alarmId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = portRuleService.getPortBlueRuleById(dtRequestDto, alarmId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @ResponseBody
    @RequestMapping("/addPortRedRule")
    public JsonMsgDto addPortRedRule(@RequestBody List<PortRedRuleDto> dtos) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(portRuleService.addPortRedRule(dtos));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/addPortBlueRule")
    public JsonMsgDto addPortBlueRule(@RequestBody List<PortBlueRuleDto> dtos) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(portRuleService.addPortBlueRule(dtos));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/deletePortRedRule")
    public JsonMsgDto deletePortRedRule(String ruleIds, Integer ruleModelId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(portRuleService.deletePortRedRule(ruleIds, ruleModelId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/deletePortBlueRule")
    public JsonMsgDto deletePortBlueRule(String ruleIds, Integer alarmId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(portRuleService.deletePortBlueRule(ruleIds, alarmId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/addRedRule")
    public JsonMsgDto addRedRule(PortRedRuleDto redRuleDto){
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(portRuleService.addRedRule(redRuleDto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/addBlueRule")
    public JsonMsgDto addBlueRule(PortBlueRuleDto blueRuleDto){
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(portRuleService.addBlueRule(blueRuleDto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }
}
